import 'package:flutter/material.dart';
import 'package:flutter_anim_test/custom/slide_power_btn2.dart';

import 'frosted_glass_widget.dart';
import 'loading_button.dart';

class CustomWidgetPage extends StatefulWidget {
  const CustomWidgetPage({super.key});

  @override
  State<CustomWidgetPage> createState() => _CustomWidgetPageState();
}

class _CustomWidgetPageState extends State<CustomWidgetPage> {
  @override
  void initState() {
    super.initState();
  }

  final SlidePowerButtonCtrl ctrl = SlidePowerButtonCtrl();
  final LoadingButtonCtrl loadingCtrl = LoadingButtonCtrl();

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        backgroundColor: Theme.of(context).colorScheme.inversePrimary,
        title: Text("自定义Widget测试"),
      ),
      body: SingleChildScrollView(
        padding: const EdgeInsets.all(8),
        child: Column(
          spacing: 16,
          children: [
            Row(
              spacing: 10,
              children: [
                SlidePowerButton2(
                    ctrl: ctrl,
                    onToggle: (b) async {
                      await Future.delayed(Duration(seconds: 3));
                      return true;
                    }),
                FilledButton(
                    onPressed: () {
                      ctrl.toggle(!ctrl.isOn);
                    },
                    child: Text("执行"))
              ],
            ),
            Row(
              spacing: 10,
              children: [
                LoadingButton(
                    ctrl: loadingCtrl,
                    onBgColor: Colors.red,
                    offBgColor: Colors.grey,
                    onToggle: (b) async {
                      await Future.delayed(Duration(seconds: 3));
                      return true;
                    }),
                FilledButton(
                    onPressed: () {
                      loadingCtrl.toggle(!loadingCtrl.isOn);
                    },
                    child: Text("执行"))
              ],
            ),
            FrostedGlassWidget(),
          ],
        ),
      ),
    );
  }

  @override
  void dispose() {
    super.dispose();
  }
}
